import { BasicLayout, UserLayout } from '@/layouts'

const RouteView = {
  name: 'RouteView',
  render: (h) => h('router-view'),
}

export const constantRouterMap = [
  {
    path: '/user',
    name: 'user',
    component: UserLayout,
    children: [
      {
        path: '/user/login',
        name: 'login',
        component: () => import('@/views/user/Login'),
      },
      {
        path: '/user/register',
        name: 'register',
        component: () => import('@/views/user/Register'),
      },
    ],
  },

  {
    path: '/404',
    component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404'),
  },
]

export const systemRouterMap = [
  {
    path: '/index',
    name: 'index',
    component: BasicLayout,
    meta: { title: '信贷后台', permission: 'system_admin' },
    redirect: '/index/dashboard',
    children: [
      // dashboard
      {
        path: '/index/dashboard',
        name: 'dashboard',
        // redirect: '/dashboard/welcome',
        component: () => import('@/views/dashboard/Welcome'),
        meta: { title: '工作台', icon: 'dashboard', permission: 'workbench' },
      },

      {
        path: '/index/account',
        component: RouteView,
        hidden: true,
        redirect: '/index/account/settings',
        name: 'account',
        meta: { title: 'menu.account', icon: 'user', keepAlive: true, permission: 'system_admin' },
        children: [
          {
            path: '/index/account/settings',
            name: 'settings',
            component: () => import('@/views/account/settings/Index'),
            meta: { title: 'menu.account.settings', hideHeader: true },
            redirect: '/index/account/settings/basic',
            hideChildrenInMenu: true,
            children: [
              {
                path: '/index/account/settings/basic',
                name: 'BasicSettings',
                component: () => import('@/views/account/settings/BasicSetting'),
                meta: { title: '基本设置', hidden: true },
              },
            ],
          },
        ],
      },

      // 借款管理
      {
        path: '/index/loan',
        name: 'loan',
        meta: {
          title: '借款管理',
          icon: 'form',
          permission: 'loan_management'
        },
        component: RouteView,
        redirect: '/index/loan/examine/await',
        children: [
          {
            path: '/index/loan/examine/await',
            name: 'ExamineAwait',
            meta: {
              title: '待审核订单',
              permission: 'pending_orders'
            },
            component: () => import('@/views/credit/loan/examine/await/Index.vue'),
          },

          {
            path: '/index/loan/appropriation/exception',
            name: 'AppropriationException',
            meta: {
              title: '异常拨款订单',
              permission: 'abnormal_orders'
            },
            component: () => import('@/views/credit/loan/appropriation/exception/Index.vue'),
          },

          {
            path: '/index/loan/disbursed/order',
            name: 'disbursed',
            meta: {
              title: '已放款订单',
              permission: 'loaned_orders'
            },
            component: () => import('@/views/credit/loan/disbursed/order/Index.vue'),
          },

          {
            path: '/index/loan/refuse/order',
            name: 'Refuse',
            meta: {
              title: '拒绝订单',
              permission: 'refused_orders'
            },
            component: () => import('@/views/credit/loan/refuse/order/Index.vue'),
          },

          {
            path: '/index/loan/all-orders/order',
            name: 'AllOrders',
            meta: {
              title: '全部订单',
              permission: 'all_orders'
            },
            component: () => import('@/views/credit/loan/all-orders/order/Index.vue'),
          },

          // 借款详情
          {
            path: '/index/loan/details',
            name: 'ExamineAwaitDetails',
            hidden: true,
            meta: {
              title: '借款详情',
            },
            redirect: '/index/loan',
            component: () => import('@/views/credit/loan/details/OrderLayout.vue'),
            children: [
              {
                path: '/index/loan/details/:tid/content',
                name: 'ExamineAwaitContent',
                component: () => import('@/views/credit/loan/details/content'),
                meta: { title: '审核内容' },
              },
              {
                path: '/index/loan/details/:tid/record',
                name: 'ExamineAwaitRecord',
                component: () => import('@/views/credit/loan/details/record'),
                meta: { title: '审批记录' },
              },
            ],
          },
        ],
      },

      // 还款
      {
        path: '/index/repayment',
        name: 'repayment',
        meta: {
          title: '还款管理',
          icon: 'table',
          permission: 'repayment_management'
        },
        // wNqRoA$Z
        component: RouteView,
        children: [
          {
            path: '/index/repayment/repaid',
            name: 'repaid',
            meta: {
              title: '待还订单',
              permission: 'pending_order_flow'
            },
            component: () => import('@/views/credit/repayment/repaid'),
          },
          {
            path: '/index/repayment/already-repaid',
            name: 'AlreadyRepaid',
            meta: {
              title: '已还订单',
              permission: 'repaid_order_flow'
            },
            component: () => import('@/views/credit/repayment/already-repaid'),
          },

          // 还款详情
          {
            path: '/index/repayment/details',
            name: 'RepaymentDetails',
            hidden: true,
            meta: {
              title: '还款详情',
            },
            redirect: '/index/repayment',
            component: () => import('@/views/credit/repayment/details/OrderLayout.vue'),
            children: [
              {
                path: '/index/repayment/details/:tid/:oid/content',
                name: 'RepaymentContent',
                component: () => import('@/views/credit/repayment/details/content'),
                meta: { title: '详情' },
              },
            ],
          },
        ],
      },

      // 逾期
      {
        path: '/index/be-overdue',
        name: 'BeOverdue',
        meta: {
          title: '逾期管理',
          icon: 'warning',
          permission: 'overdue_management'
        },
        component: () => import('@/views/credit/be-overdue'),
      },

      // 逾期详情
      {
        path: '/index/be-overdue/details',
        name: 'BeOverdueDetails',
        meta: {
          keepAlive: true,
          title: '逾期详情',
          icon: 'warning',
          permission: 'overdue_management'
        },
        hidden: true,
        redirect: '/index/be-overdue',
        component: () => import('@/views/credit/be-overdue/details/OrderLayout.vue'),
        children: [
          {
            path: '/index/be-overdue/details/:tid/:oid/content',
            name: 'BeOverdueContent',
            component: () => import('@/views/credit/be-overdue/details/content'),
            meta: { title: '详情' },
          },
        ],
      },

      // 营销管理
      {
        path: '/index/market',
        name: 'market',
        meta: {
          title: '营销管理',
          icon: 'smile',
          permission: 'marketing_management'
        },
        component: () => import('@/views/credit/market/info'),
      },
      // 营销详情
      {
        path: '/index/market/details/:id',
        name: 'MarketDetails',
        hidden: true,
        meta: {
          title: '营销管理',
          permission: 'marketing_management'
        },
        component: () => import('@/views/credit/market/details'),
      },

      // 注册用户管理
      {
        path: '/index/user',
        name: 'RegisterUser',
        meta: {
          title: '注册用户管理',
          icon: 'usergroup-add',
          permission: 'user_management'
        },
        component: RouteView,
        redirect: '/index/user',
        hideChildrenInMenu: true,
        children: [
          {
            path: '/index/user',
            name: 'RegisterUsers',
            meta: {
              keepAlive: true,
              title: '用户列表',
            },
            component: () => import('@/views/credit/user/info/Index.vue'),
          },
          {
            path: '/index/user/details',
            name: 'RegisterUserDetails',
            hidden: true,
            meta: {
              title: '用户详情',
            },
            redirect: '/index/user',
            component: () => import('@/views/credit/user/details/UserDetailsLayout.vue'),
            children: [
              {
                path: '/index/user/details/:uid/user',
                name: 'RegisterUserDetailsContent',
                component: () => import('@/views/credit/user/details/user/Index.vue'),
                meta: { title: '基本信息' },
              },
              {
                path: '/index/user/details/:uid/loan',
                name: 'RegisterUserDetailsLoan',
                component: () => import('@/views/credit/user/details/loan/Index.vue'),
                meta: { title: '借贷记录' },
              },
              {
                path: 'risk',
                name: 'RegisterUserDetailsRisk',
                component: () => import('@/views/credit/user/details/risk/Index.vue'),
                meta: { title: '风险报告' },
              },
            ],
          },

        ],
      },

      // 系统管理
      {
        path: '/index/system',
        name: 'system',
        meta: {
          title: '系统管理',
          icon: 'setting',
          permission: 'system_management'
        },
        component: RouteView,
        children: [
          {
            path: '/index/system/product',
            name: 'SystemProduct',
            meta: {
              title: '产品设置',
              permission: 'product_settings'
            },
            component: () => import('@/views/credit/system/product/Index.vue'),
          },
          {
            path: '/index/system/news',
            name: 'SystemNews',
            meta: {
              title: '消息设置',
              permission: 'notification_settings'
            },
            component: () => import('@/views/credit/system/news/info'),
            hideChildrenInMenu: true,
          },

          {
            path: '/index/system/news/settings',
            name: 'NewsSettings',
            meta: {
              title: '消息设置',
              permission: 'notification_settings'
            },
            hidden: true,
            redirect: '/index/system/news',
            component: () => import('@/views/credit/system/news/details/RecordLayout.vue'),
            children: [
              {
                path: '/index/system/news/settings/:id/:mode/template',
                name: 'NewsTemplate',
                component: () => import('@/views/credit/system/news/details/template'),
                meta: { title: '模板' },
              },
              {
                path: '/index/system/news/settings/:id/:mode/send-record',
                name: 'SendRecord',
                component: () => import('@/views/credit/system/news/details/send-record'),
                meta: { title: '发送记录' },
              },
            ],
          },

          {
            path: '/index/system/logs',
            name: 'SystemLogs',
            meta: {
              title: '操作日志',
              permission: 'logs'
            },
            redirect: '/index/system/logs/login',
            component: () => import('@/views/credit/system/logs/LogsLayout.vue'),
            hideChildrenInMenu: true,
            children: [
              {
                path: 'login',
                name: 'LogsLogin',
                component: () => import('@/views/credit/system/logs/login'),
                meta: { title: '登录日志' },
              },
              {
                path: 'operation',
                name: 'LogsOperation',
                component: () => import('@/views/credit/system/logs/operation'),
                meta: { title: '操作日志' },
              },
              {
                path: 'automatic-deduction',
                name: 'LogsAutomaticDeduction',
                component: () => import('@/views/credit/system/logs/automatic-deduction'),
                meta: { title: '自动扣款记录' },
              },
            ],
          },
        ],
      },

      // 数据统计
      {
        path: '/index/statistics',
        name: 'statistics',
        meta: {
          title: '数据统计',
          icon: 'form',
          permission: 'data_statistics'
        },
        component: RouteView,
        children: [
          {
            path: '/index/statistics/overview',
            name: 'StatisticsOverview',
            component: () => import('@/views/credit/statistics/overview'),
            meta: { title: '概览', permission: 'overview' },
          },
          {
            path: '/index/statistics/order-report',
            name: 'StatisticsOrder',
            component: () => import('@/views/credit/statistics/order-report/OrderReportLayout.vue'),
            meta: { title: '订单统计报表', permission: 'approved_declined_statics' },
            redirect: '/index/statistics/order-report/approved',
            hideChildrenInMenu: true,
            children: [
              {
                path: '/index/statistics/order-report/approved',
                name: 'StatisticsApproved',
                component: () => import('@/views/credit/statistics/order-report/approved'),
                meta: { title: '审核通过' },
              },
              {
                path: '/index/statistics/order-report/audit-reject',
                name: 'StatisticsAditReject',
                component: () => import('@/views/credit/statistics/order-report/audit-reject'),
                meta: { title: '审核拒绝' },
              },
            ],
          },
          // {
          //   path: '/index/statistics/expire-report',
          //   name: 'StatisticsExpire',
          //   component: () => import('@/views/credit/statistics/expire-report'),
          //   meta: { title: '到期未还报表'},
          // },
          // {
          //   path: '/index/statistics/bad-debt-report',
          //   name: 'StatisticsBadDebt',
          //   component: () => import('@/views/credit/statistics/bad-debt-report'),
          //   meta: { title: '坏账报表'},
          // },
          {
            path: '/index/statistics/account-report',
            name: 'StatisticsAccount',
            component: () => import('@/views/credit/statistics/account-report'),
            meta: { title: '注册用户报表', permission: 'registered_users_reports' },
          },
        ],
      },
    ],
  },

  // 网站后台
  {
    path: '/website',
    name: 'website',
    component: BasicLayout,
    meta: { title: '官网后台', permission: 'company_website' },
    redirect: '/website/feedback',
    children: [
      // 用户反馈
      {
        path: '/website/feedback',
        name: 'feedback',
        component: () => import('@/views/website/feedback/info'),
        meta: {
          title: '用户反馈',
          icon: 'dashboard',
          permission: 'user_feedback'
        },
      },
      {
        path: '/website/feedback/details',
        name: 'FeedbackDetails',
        hidden: true,
        component: () => import('@/views/website/feedback/details/FeedbackLayout.vue'),
        meta: {
          title: '用户反馈',
          permission: 'user_feedback'
        },
        redirect: '/website/feedback',
        children: [
          {
            path: '/website/feedback/details/:id/content',
            name: 'FeedbackContent',
            component: () => import('@/views/website/feedback/details/content'),
            meta: { title: '详情' },
          }
        ]
      },
      
      // blog
      {
        path: '/website/blog',
        name: 'WebsiteBlog',
        component: () => import('@/views/website/blog/info'),
        meta: { title: 'Blog', icon: 'form', permission: 'Blog' },
      },
      {
        path: '/website/blog/details',
        name: 'BlogDetails',
        hidden: true,
        component: () => import('@/views/website/blog/details/BlogLayout.vue'),
        meta: { title: 'Blog', permission: 'Blog' },
        redirect: '/website/blog',
        children: [
          {
            path: '/website/blog/details/:id/content',
            name: 'BlogContent',
            component: () => import('@/views/website/blog/details/content'),
            meta: { title: '详情', permission: 'Blog' },
          }
        ]
      },

      // FAQ
      {
        path: '/website/FAQ',
        name: 'WebsiteFAQ',
        component: () => import('@/views/website/FAQ/info'),
        meta: { title: 'FAQ', icon: 'form', permission: 'FAQ' },
      },
      {
        path: '/website/FAQ/details',
        name: 'FAQDetails',
        hidden: true,
        component: () => import('@/views/website/FAQ/details/FAQLayout.vue'),
        meta: { title: 'FAQ', permission: 'FAQ' },
        redirect: '/website/FAQ',
        children: [
          {
            path: '/website/FAQ/details/:id/content',
            name: 'FAQContent',
            component: () => import('@/views/website/FAQ/details/content'),
            meta: { title: '详情' },
          }
        ]
      },
      // {
      //   path: '/website/FAQ',
      //   name: 'FAQ',
      //   component: () => import('@/views/website/FAQ'),
      //   meta: { title: 'FAQ', icon: 'table' },
      // },
    ],
  },

  // 风控引擎
  {
    path: '/risk-engine',
    name: 'risk-engine',
    component: BasicLayout,
    meta: { title: '风控引擎', permission: 'risk_engine' },
    redirect: '/risk-engine/quota',
    children: [
      // 风控指标
      {
        path: '/risk-engine/quota',
        name: 'RiskQuota',
        component: () => import('@/views/risk-engine/quota/info'),
        meta: { title: '风控指标', icon: 'dashboard', permission: 'risk_indicators' },
        // redirect: '/risk-engine/quota/info',
      },
      {
        hidden: true,
        path: '/risk-engine/quota/modify/:id',
        name: 'ModifyQuota',
        component: () => import('@/views/risk-engine/quota/details'),
        meta: { title: '修改指标', permission: 'risk_indicators' },
      },

      // 额度模型
      {
        path: '/risk-engine/decision-mak-model',
        name: 'DecisionMakModel',
        component: () => import('@/views/risk-engine/decision-mak-model/info'),
        meta: { title: '决策模型', icon: 'table', permission: 'decision_models' },
      },
      {
        hidden: true,
        path: '/risk-engine/decision-mak-model/modify/:id',
        name: 'ModifyDecisionMakModel',
        component: () => import('@/views/risk-engine/decision-mak-model/details'),
        meta: { title: '新建规则集', permission: 'decision_models' },
      },

       // 额度模型
       {
        path: '/risk-engine/quota-model',
        name: 'QuotaModel',
        component: () => import('@/views/risk-engine/quota-model/info'),
        meta: { title: '额度模型', icon: 'table', permission: 'amount_models' },
      },
      {
        hidden: true,
        path: '/risk-engine/quota-model/modify/:id',
        name: 'ModifyQuotaModel',
        component: () => import('@/views/risk-engine/quota-model/details'),
        meta: { title: '新建规则集', permission: 'amount_models' },
      },
      // {
      //   path: '/risk-engine/rule/manage',
      //   name: 'RiskRuleManage',
      //   component: RouteView,
      //   meta: { title: '规则管理', icon: 'dashboard' },
      //   redirect: '/risk/rule/manage/configure',
      //   children: [
      //     {
      //       path: '/risk/rule/manage/configure',
      //       name: 'RiskRuleConfigure',
      //       component: () => import('@/views/risk/rule/configure'),
      //       meta: { title: '规则配置' },
      //     },
      //     {
      //       path: '/risk/rule/manage/rules',
      //       name: 'RiskRules',
      //       component: () => import('@/views/risk/rule/rules'),
      //       meta: { title: '规则集' },
      //     },
      //   ],
      // },

      // {
      //   path: '/risk/score-card',
      //   name: 'RiskScoreCard',
      //   component: () => import('@/views/risk/score-card'),
      //   meta: { title: '评分卡', icon: 'dashboard' },
      // },

      // {
      //   path: '/risk/model/manage',
      //   name: 'RiskModelManage',
      //   component: RouteView,
      //   meta: { title: '模型管理', icon: 'dashboard' },
      //   redirect: '/risk/model/manage/models',
      //   children: [
      //     {
      //       path: '/risk/rule/manage/models',
      //       name: 'RiskModels',
      //       component: () => import('@/views/risk/rule/configure'),
      //       meta: { title: '模型列表' },
      //     },
      //     {
      //       path: '/risk/rule/manage/rules',
      //       name: 'RiskRules',
      //       component: () => import('@/views/risk/rule/rules'),
      //       meta: { title: '模型评估' },
      //     },
      //   ],
      // },

    ],
  },

  // 角色权限
  {
    path: '/role',
    name: 'role',
    component: BasicLayout,
    meta: { title: '角色权限', permission: 'role_authorization' },
    redirect: '/role/account',
    children: [
      {
        path: '/role/account',
        name: 'RoleAccount',
        component: () => import('@/views/role/account/information/Index.vue'),
        meta: { title: '账号管理', icon: 'dashboard', permission: 'admin_user_management' },
      },
      {
        path: '/role/jurisdiction',
        name: 'Jurisdiction',
        component: () => import('@/views/role/jurisdiction/groups/Index.vue'),
        meta: { title: '权限管理', icon: 'form', permission: 'privilege_management' },
      },

      // account modify
      {
        path: '/role/account/add',
        name: 'AccountAdd',
        hidden: true,
        component: () => import('@/views/role/account/details/add/Index.vue'),
        meta: { title: '新增用户', permission: 'admin_user_management' },
      },

      {
        path: '/role/account/:uid',
        name: 'AccountDetails',
        hidden: true,
        component: () => import('@/views/role/account/details/info/Index.vue'),
        meta: { title: '详情', permission: 'admin_user_management' },
      },
      {
        path: '/role/account/modify/:uid',
        name: 'AccountEdit',
        hidden: true,
        component: () => import('@/views/role/account/details/modify/Index.vue'),
        meta: { title: '编辑', permission: 'admin_user_management' },
      },

      // jurisdiction
      {
        path: '/role/jurisdiction/add',
        name: 'JurisdictionAdd',
        hidden: true,
        component: () => import('@/views/role/jurisdiction/details/add/Index.vue'),
        meta: { title: '新建', permission: 'privilege_management' },
      },
      {
        path: '/role/jurisdiction/:gid',
        name: 'JurisdictionDetails',
        hidden: true,
        component: () => import('@/views/role/jurisdiction/details/info/Index.vue'),
        meta: { title: '详情', permission: 'privilege_management' },
      },
      {
        path: '/role/jurisdiction/modify/:gid',
        name: 'JurisdictionEdit',
        hidden: true,
        component: () => import('@/views/role/jurisdiction/details/modify/Index.vue'),
        meta: { title: '编辑', permission: 'privilege_management' },
      },
    ],
  },

  {
    path: '*', redirect: '/index', hidden: true,
  },
]

export const asyncRouterMap = [
  {
    path: '*', redirect: '/404', hidden: true,
  },
]
